package me.caofeng.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.util.Date;


/**
 * Copyright © 2017曹峰. All rights reserved.
 *
 * @Prject: mall
 * @Package: me.caofeng.util
 * @Description: 时间转换工具类
 * @Author: 曹峰 blog.caofeng.me
 * @Date: 2017-07-01 0:28
 * @Version: V1.0
 */
public class DateUtil {
    private static Logger LOGGER = LogManager.getLogger(DateUtil.class);
    public static final String STANDARD_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static Date stringToDate(String timestamp) {
        if (CheckUtil.isEmpty(timestamp)){
            return null;
        }
        DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(STANDARD_FORMAT);
        DateTime dateTime = dateTimeFormatter.parseDateTime(timestamp);
        return dateTime.toDate();
    }

    public static void main(String[] args) {
        String s = "22017-07-01 19:09:12";
        LOGGER.info(stringToDate(s));
    }
}
